<div class="crumb-wrap">
    <div class="crumb-list"><i class="icon-font"></i><a href="<?=site_url('admini')?>">首页</a>
        <span class="crumb-step">&gt;</span><a class="crumb-name" href="<?=site_url('admini/goods')?>">商品管理</a></span>
        <span class="crumb-step">&gt;</span><span class="crumb-name">商品信息</span>
    </div>
</div>

<div class="search-wrap">
    <div class="search-content">
        <table class="search-tab">
            <tr>
                <td style="padding-left: 20px;"><input class="btn btn6 btn-primary" value="商品信息录入" type="button"></td>
                <td style="padding-left: 20px;"><input class="btn btn6" value="商品详情" type="button"></td>
                <td style="padding-left: 20px;"><input class="btn btn7" value="商品属性（一）" type="button"></td>
                <td style="padding-left: 20px;"><input class="btn btn7" value="商品属性（二）" type="button"></td>
                <td style="padding-left: 20px;"><input class="btn btn6" value="商品评论管理" type="button"></td>
            </tr>
        </table>
    </div>
</div>

<div class="result-wrap">
    <div class="result-content">
        <form action="<?=site_url('admini/goods/edit_goods')?>" method="post" id="myform" name="myform" enctype="multipart/form-data">
            <table class="insert-tab" width="100%">
                <tbody><tr>
                    <th width="220"><i class="require-red">*</i>商品分类：</th>
                    <td id="sort">
                        <select name="sort_id" id="catid" class="required top_0" onchange="getsort(0,this.value)">
                        	<option value="0">请选择分类</option>
                        	<?php foreach($sort_list as $k => $v):?>
                            <option value="<?=$v['id']?>"><?=$v['name']?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>商品名称：</th>
                    <td>
                        <input class="common-text required" id="title" name="name" size="50" value="" type="text">
                    </td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>商品数量：</th>
                    <td><input class="common-text" name="num" size="50" value="" type="text"></td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>品牌名称：</th>
                    <td><input class="common-text" name="brand" size="50" value="" type="text"></td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>商品产地：</th>
                    <td><input class="common-text" name="origin" size="50" value="中国大陆" type="text"></td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>商品上架时间：</th>
                    <td><input class="common-text" name="shelves_time" size="50" value="<?=date('Y-m-d')?>" type="text" readonly id="date"></td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>商品价格：</th>
                    <td><input class="common-text" name="price" size="50" value="" type="text"></td>
                </tr>
                <tr>
                    <th>实体店价格：</th>
                    <td>
                    	<input class="common-text" name="sprice" size="50" value="" type="text">
                    	<span><i class="require-red">*</i>实体店价格为空，则前端不显示</span>
                    </td>
                </tr>
                <tr>
                    <th><i class="require-red">*</i>包装清单：</th>
                    <td><input class="common-text" name="packaging" size="80" value="" type="text"></td>
                </tr>
                <tr>
                    <th>商品描述（最多225个字）：</th>
                    <td><textarea name="describe" class="common-textarea" id="content" cols="30" style="width: 60%;" rows="10"></textarea></td>
                    
                </tr>
                <tr>
                    <th></th>
                    <td>
                    	
                    	<!-- 需求数据 -->
                    	<input type="hidden" name="id" value="<?=$res['id']?>" />
                    	<input type="hidden" name="status" value="<?=$res['status']?>" />
                    	
                        <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                        <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                        <span>有<i class="require-red">*</i>符号的为必填项</span>
                    </td>
                </tr>
                </tbody></table>
        </form>
    </div>
</div>
<!-- 导入日历插件 -->
<script type="text/javascript" src="<?=base_url('public/lib/laydate/laydate.js')?>"></script>

<script>
!function(){
	laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
	laydate({elem: '#date'});//绑定元素
}();


//日期范围限定在昨天到明天
laydate({
    elem: '#date',
    min: laydate.now(-1), //-1代表昨天，-2代表前天，以此类推
});

	$('#myform').submit(function() {
            $(this).ajaxSubmit(function(data){
                if(data == 1){
                    layer.alert('新增商品成功，请继续添加其他属性',{
                        icon:1,
                    },function(){
                    	//alert(1);
                    	location.href="<?=site_url('admini/details/update?gid='.$res['id'])?>";
                    });
                }else{
                    layer.alert(data,{
                        icon:2,
                    });
                }
            })
            return false;
        })
	
	//ajax联动菜单
	function getsort(top,pid){
		
		//删除
		var k = top*1+1;
		$("#sort select").each(function(){
			$(".top_"+k).remove();
			k ++;
		})
		if(pid == 0){
			return false;
		}
		
		//判断是否是上级分类
		var sv = $(".top_"+(top*1-1)).val();
		if(sv === pid){
			return false;
		}
		
		$.post("<?=site_url('admini/sort/getsort')?>",{sid:pid},function(data){
			if(data == ''){
				return false;
			}
			var l = '<select name="sort_id" id="catid" class="required top_'+(top*1+1)+'" onchange="getsort('+(top*1+1)+',this.value)">';
			
			$(data).each(function(){
				l += '<option value="'+this.id+'">'+this.name+'</option>';
			})
			l += '</select>';
			$(".top_"+top).after(l);
		},'json');
	}
</script>